Skip to content

fix!: stop deleting $CARGO_HOME during uninstall#4861

Draft
Cloud0310 wants to merge 10 commits into
rust-lang:mainfrom
Cloud0310:main
Draft

fix!: stop deleting $CARGO_HOME during uninstall#4861
Cloud0310 wants to merge 10 commits into
rust-lang:mainfrom
Cloud0310:main

Conversation

@Cloud0310
Copy link
Copy Markdown
Contributor

fix #285
This PR fix the cargo bin nuke and the path removing possilble toutoc issue.
Here's the implementation details:

  • compare cargo bin dir content to rustup binary, if it's a link, remove it
  • then, we remove the rustup binary, on success, we then remove the cargo bin from path

This prevents rustup self uninstall from nuking out the $CARGO_HOME/bin and possible toctou problem of removing up the path.

Comment thread tests/suite/cli_self_upd.rs
@Cloud0310 Cloud0310 marked this pull request as ready for review May 19, 2026 10:37
@Cloud0310
Copy link
Copy Markdown
Contributor Author

Cloud0310 commented May 19, 2026

I think I may need more tests against this PR, this includes:

  • $CARGO_HOME/bin with unrelated files
  • empty bin cleanup test

Should there be more tests? Please let me know @FranciscoTGouveia @rami3l .

Comment thread src/cli/self_update/unix.rs Outdated
Comment thread src/cli/self_update/unix.rs Outdated
Comment thread tests/suite/cli_self_upd.rs Outdated
Comment thread src/cli/self_update.rs Outdated
Comment thread src/cli/self_update/unix.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update.rs Outdated
Comment thread src/cli/self_update.rs Outdated
@Cloud0310
Copy link
Copy Markdown
Contributor Author

I've add more tests about the PR here. Please review.

Comment thread src/cli/self_update/unix.rs Outdated
Copy link
Copy Markdown
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo some tiny nits, nice work :D

View changes since this review

Comment thread src/cli/self_update.rs Outdated
Comment thread tests/suite/cli_self_upd.rs Outdated
Comment thread tests/suite/cli_self_upd.rs
@Cloud0310 Cloud0310 force-pushed the main branch 2 times, most recently from 4a4880a to 971dffa Compare May 22, 2026 08:13
Cloud0310 added a commit to Cloud0310/rustup that referenced this pull request May 22, 2026
Avoid removing $CARGO_HOME when running uninstall cleanup.

Combine all follow-up work for PR rust-lang#4861:

- keep $CARGO_HOME/bin when it is non-empty

- cover cargo bin cleanup behavior in uninstall tests

- update uninstall cleanup comments and related docs

- rename cleanup internals for clearer intent
Cloud0310 added a commit to Cloud0310/rustup that referenced this pull request May 22, 2026
Avoid removing $CARGO_HOME when running uninstall cleanup.

Combine all follow-up work for PR rust-lang#4861:

- keep $CARGO_HOME/bin when it is non-empty

- cover cargo bin cleanup behavior in uninstall tests

- update uninstall cleanup comments and related docs

- rename cleanup internals for clearer intent
@rustbot

This comment has been minimized.

Cloud0310 added a commit to Cloud0310/rustup that referenced this pull request May 22, 2026
Avoid removing $CARGO_HOME when running uninstall cleanup.

Combine all follow-up work for PR rust-lang#4861:

- keep $CARGO_HOME/bin when it is non-empty

- cover cargo bin cleanup behavior in uninstall tests

- update uninstall cleanup comments and related docs

- rename cleanup internals for clearer intent
Copy link
Copy Markdown
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR needs a bunch of work, it seems to have a lot of changes together in a single commit that are pretty messy. It would be good if the commit history made it clear that there are a sequence of smaller changes being made.

View changes since this review

Comment thread src/cli/self_update/unix.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update/windows.rs
Cloud0310 added a commit to Cloud0310/rustup that referenced this pull request May 22, 2026
Avoid removing $CARGO_HOME when running uninstall cleanup.

Combine all follow-up work for PR rust-lang#4861:

- keep $CARGO_HOME/bin when it is non-empty

- cover cargo bin cleanup behavior in uninstall tests

- update uninstall cleanup comments and related docs

- rename cleanup internals for clearer intent
Cloud0310 added a commit to Cloud0310/rustup that referenced this pull request May 22, 2026
Avoid removing $CARGO_HOME when running uninstall cleanup.

Combine all follow-up work for PR rust-lang#4861:

- keep $CARGO_HOME/bin when it is non-empty

- cover cargo bin cleanup behavior in uninstall tests

- update uninstall cleanup comments and related docs

- rename cleanup internals for clearer intent
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 1, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Cloud0310 Cloud0310 force-pushed the main branch 3 times, most recently from afd4a48 to 6e27966 Compare June 1, 2026 13:54
@rami3l rami3l marked this pull request as draft June 1, 2026 14:17
@rami3l
Copy link
Copy Markdown
Member

rami3l commented Jun 1, 2026

@Cloud0310 Since your PR needs more work, I've marked this PR as draft.

Please address or at least respond to all open threads before marking this PR as "ready for review" again, at which point the team will return for another round of review, thanks 🙏

@Cloud0310 Cloud0310 force-pushed the main branch 7 times, most recently from 2acb9ec to 1c41abe Compare June 5, 2026 16:09
@Cloud0310 Cloud0310 force-pushed the main branch 2 times, most recently from 781981d to 197f611 Compare June 6, 2026 17:04
Copy link
Copy Markdown
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking much better than before! I have a few final nits; address them in addition to the remaining ones and we should be good to go 🙏

View changes since this review

Comment thread src/cli/self_update.rs Outdated
utils::remove_dir("rustup_home", &rustup_dir)?;
}

// Clean up rustup tool links
Copy link
Copy Markdown
Member

@rami3l rami3l Jun 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Logically this snippet should be placed after the "for dirent in diriter {" block, since the removal of cargo home should start after that.

Comment thread src/cli/self_update/unix.rs Outdated
@Cloud0310 Cloud0310 force-pushed the main branch 2 times, most recently from fd7441d to dac53d8 Compare June 7, 2026 15:17
Cloud0310 added 5 commits June 7, 2026 23:43
On Windows, rustup cannot delete the running rustup.exe directly. The uninstall path spawns rustup-gc-* and lets that child finish cleanup after the parent process exits.

PATH cleanup now depends on whether the gc process successfully removes /home/cloud/.cargo/bin. That means the parent's --no-modify-path choice has to be passed to the gc process. Use a private environment variable for that one-way handoff because this is an internal child process, not a public CLI invocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop nuking $CARGO_HOME (~/.cargo) on rustup self uninstall

5 participants